import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class main {
    public static void main(String[] args) {
        ClassGroup c1 = new ClassGroup("一年级一班");
        Group g1 = new Group("A组");
        Group g2 = new Group("B组");
        c1.addGroup(g1);
        c1.addGroup(g2);
        Student s1 = new Student("小明", 10, g1);
        Student s2 = new Student("小红", 11, g1);
        Student s3 = new Student("小刚", 12, g2);
        Student s4 = new Student("小丽", 13, g2);
        g1.addStudent(s1);
        g1.addStudent(s2);
        g2.addStudent(s3);
        g2.addStudent(s4);
        c1.addStudent(s1);
        c1.addStudent(s2);
        c1.addStudent(s3);
        c1.addStudent(s4);
        System.out.println(c1);
        Group randomGroup = getRandomGroup(c1.getGroups());
        System.out.println("随机抽取的小组: " + randomGroup);
        Student randomStudentFromGroup = getRandomStudent(randomGroup.getStudents());
        System.out.println("随机抽取的学生: " + randomStudentFromGroup);
        Student randomStudentFromClass = getRandomStudent(c1.getAllStudents());
        System.out.println("随机抽取的全班学生: " + randomStudentFromClass);
    }
    private static <T> T getRandomElement(List<T> list) {
        Random random = new Random();
        int index = random.nextInt(list.size());
        return list.get(index);
    }
    private static Group getRandomGroup(List<Group> groups) {
        return getRandomElement(groups);
    }
    private static Student getRandomStudent(List<Student> students) {
        return getRandomElement(students);
    }
}